//
//  JPVistorViewController.swift
//  JPWeibo
//
//  Created by 哇咔咔 on 16/9/20.
//  Copyright © 2016年 jp. All rights reserved.
//

import UIKit

class JPVistorViewController: UITableViewController {
    
    var isLogin: Bool = JPUserInfoViewModel.sharedUserInfoViewModel.isLogin
    
    var vistorView: JPVistorView?
    
    override func loadView() {
        
        if isLogin {
            
            super.loadView()
        }else {
            
//            vistorView = JPVistorView(frame: UIScreen.main.bounds, title: nil, imageName: nil)
            vistorView?.loginClosure = { [weak self] in
                self?.requestLoginOperation()
            }
            vistorView?.registerClosure = {
                print("注册")
            }
            view = vistorView
            setupNavUI()
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        
    }
    
    func setupNavUI() {
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", imageName: nil, target: self, action: #selector(clickToLogin))
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", imageName: nil, target: self, action: #selector(registerToLogin))
    }
    
    func clickToLogin() {
        
        requestLoginOperation()
    }

    func registerToLogin() {
        
        print("注册")
    }
    
    func requestLoginOperation() {
        
        let oAuthView = JPOAuthViewController()
        let nav = JPNavigationController(rootViewController: oAuthView)
        
        present(nav, animated: true, completion: nil)
        
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

}
